package com.coolyu.lab.server;

import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import com.coolyu.lab.data.*;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class TestVote extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)throws IOException {
		
		VoteObject voteObject = new VoteObject(req.getRemoteAddr(),new Date().toString(),"test");
		PersistenceManager vf = VoteFactory.getInstance().getPersistenceManager();
		vf.makePersistent(voteObject);
		vf.close();
		vf = VoteFactory.getInstance().getPersistenceManager();
		Query q = vf.newQuery("SELECT FROM " + VoteObject.class.getName());
        List<VoteObject> list = null;
        list = (List<VoteObject>)q.execute();
        Iterator i = list.iterator();
        while(i.hasNext()){
        	VoteObject gd = (VoteObject)i.next();
        	resp.getWriter().println(gd.getIP() + gd.getTime() + gd.getChoice());
        }
        vf.close();
	}

}
